<?php

namespace app\admin\controller\zzcash;

use addons\zzcash\model\OutM;
use addons\zzcash\service\PayS;
use app\common\controller\Backend;

class Out extends Backend
{
    protected $model          = null;
    protected $relationSearch = true;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new OutM();
        $this->assignconfig('payed_is_map', [
            'yes' => '是',
            'no'  => '否',
        ]);
    }

    public function index()
    {
        $this->request->filter(['strip_tags', 'trim']);
        if (!$this->request->isAjax()) {
            return $this->fetch();
        }
        if ($this->request->request('keyField')) {
            return $this->selectpage();
        }
        [$where, $sort, $order, $offset, $limit] = $this->buildparams();
        $list = $this->model->with([
            'admin',
            'user',
        ])->where($where)->order($sort, $order)->paginate($limit);
        return json([
            'total' => $list->total(),
            'rows'  => $list->items(),
        ]);
    }

    public function do($ids)
    {
        if (!$this->request->isAjax()) {
            PayS::transfer(OutM::find($ids));
        }
        $this->success();
    }
}
